package com.say.config;

import java.io.File;
import java.io.FileNotFoundException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.say.interceptor.AuthInterceptor;
import com.say.interceptor.DataInterceptor;
import com.say.utils.SysParentFile;

/**
 * Created by Administrator on 2019/1/20.
 */

@Configuration
public class ResourceConfig extends WebMvcConfigurerAdapter {
	@Autowired
    private  AuthInterceptor   authInterceptor;
	
	@Autowired
    private  DataInterceptor   dataInterceptor;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		
		//将所有/static/** 访问都映射到classpath:/static/ 目录下
		
		registry.addResourceHandler("/static/upload/**").addResourceLocations("file:"+SysParentFile.getParentFile()+"/");
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/favicon.ico");
	}
	
    @Override
    public void addInterceptors(InterceptorRegistry  registry) {
    	InterceptorRegistration interceptor1 = registry.addInterceptor(dataInterceptor);
    	// 排除配置
    	interceptor1.excludePathPatterns("/static/**");
    	interceptor1.excludePathPatterns("classpath:/static/");
    	interceptor1.excludePathPatterns("classpath:/favicon.ico");
    	interceptor1.addPathPatterns("/**");// 拦截配置
    	
    	
    	InterceptorRegistration interceptor2 = registry.addInterceptor(authInterceptor);
    	// 排除配置
    	interceptor2.excludePathPatterns("/static/**");
    	interceptor2.excludePathPatterns("classpath:/static/");
    	interceptor2.excludePathPatterns("classpath:/favicon.ico");
    	interceptor2.addPathPatterns("/wensay/**");// 拦截配置
    }
}


